﻿

namespace Forest.Lion.Web.Models {
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Security.Principal;
    using Forest.Lion.Domain.Models;
    using System.Web.Security;

    [Serializable]
    public class AppIdentity : IIdentity {
        public AppIdentity(string name, string displayName, Guid userId) {
            this.Name = name;
            this.DisplayName = displayName;
            this.UserId = userId;
        }

        public AppIdentity(string name, UserInfo userInfo)
            : this(name, userInfo.OrganizationName, userInfo.UserId) {
            if (userInfo == null)
                throw new ArgumentNullException("userInfo");
            this.UserId = userInfo.UserId;
        }

        public AppIdentity(FormsAuthenticationTicket ticket)
            : this(ticket.Name, UserInfo.FromString(ticket.UserData)) {
            if (ticket == null)
                throw new ArgumentNullException("ticket");
        }

        public string Name { get; private set; }

        public string AuthenticationType {
            get { return "App"; }
        }

        public bool IsAuthenticated {
            get { return true; }
        }

        public string DisplayName { get; private set; }

        public Guid UserId { get; private set; }
    }
}